<!--
 * @Description: 商务成本计划管理
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2024-03-01 11:07:56
 * @LastEditTime: 2024-03-29 13:01:03
 * @FilePath: \cscec-pms-admin\src\views\businessAffairs\businessCostPlanManagement\costPlanManagement\CostPlan\index.vue
-->
<template>
  <base-breadcrumb>
    <a-card class="card-wrapper" v-if="!isErr">
      <fullScreen />
      <a-tabs v-model="key">
        <a-tab-pane
          key="1"
          :tab="notProjectId ? '目标成本分解查看' : '成本初始化'"
        >
          <TargetCostDecomposition v-if="notProjectId" />
          <InformationInit
            v-else
            :isInit="isInit"
            @approve="handleApprove"
          />
        </a-tab-pane>
        <a-tab-pane
          key="2"
          tab="成本填报"
        >
          <InformationFilling />
        </a-tab-pane>
        <a-tab-pane
          key="3"
          tab="成本调整"
        >
          <InformationAdjustment />
        </a-tab-pane>
        <span slot="tabBarExtraContent" class="unit">单位：元</span>
      </a-tabs>
    </a-card>
    <div v-else style="display: flex;align-items: center;justify-content: center;height: 100%;">
      <p style="font-size: 24px;">该项目无权限访问此页面</p>
    </div>
  </base-breadcrumb>
</template>
<script>
import TargetCostDecomposition from './components/TargetCostDecomposition'
import InformationInit from './components/InformationInit'
import InformationFilling from './components/InformationFilling'
import InformationAdjustment from './components/InformationAdjustment'
import { getCostPlanTwo} from '@/api/businessAffairs/costAccountInit'
import fullScreen from '../../headquartersDashboard/components/fullScreen/fullScreen.vue'
export default {
  name: 'costPlan' + Date.now(),
  components: {
    TargetCostDecomposition,
    InformationInit,
    InformationFilling,
    InformationAdjustment,
    fullScreen
  },
  data() {
    return {
      // 项目id
      projectId: this.$userInfo()?.currentPost?.projectId,
      // 页面key
      key: '',
      // 初始状态
      isInit: true,
      isErr:false,
    }
  },
  mounted() {
    this.key = '1'
    if(this.projectId){
        this.getTableData()
    }
  },
  watch: {
    key: {
      handler(newV, oldV) {
        if (oldV !== '') {
          this.isInit = false
        }
        // key变化时广播出去
        window.postMessage({ name: 'init', key: newV }, window.location.origin)
      }
    }
  },
  computed: {
    // 没有项目id
    notProjectId() {
      return (this.projectId ?? '') === ''
    }
  },
  methods: {
    /**
     * @description: 初始进入页面时审批通过默认跳转
     * @return {void}
     */
    handleApprove() {
      if (this.isInit) {
        this.key = '2'
      }
    },
    getTableData() {
      let req = {
        projectId: this.projectId,
        isHide: false
      }
      getCostPlanTwo(req)
        .then((res) => {
          if(res.code == '501'){
            this.isErr = true;
            //this.$message.warning(res.msg)
          }else{
            this.isErr = false;
          }
        })
    },
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.card-wrapper {
  height: 100%;
  margin-bottom: 0;
  @{deep} .ant-card-body,
  .ant-tabs,
  .ant-tabs-tabpane,
  .ant-spin-nested-loading {
    height: 100%;
  }
  .ant-tabs {
    @{deep} .ant-tabs-content {
      height: calc(100% - 54px);
    }
  }
  .ant-spin-nested-loading {
    @{deep} .ant-spin-container {
      height: 100%;
    }
  }
  @{deep} .ant-card-body{
    padding: 0px 10px;
  }
  .unit{
    margin-right: 50px;
  }
}
</style>
